package cn.puge.mertisfront.controller;


import cn.puge.commonutils.R;
import cn.puge.mertisfront.entity.TestOrder;
import cn.puge.mertisfront.entity.TestPayDes;
import cn.puge.mertisfront.service.TestOrderService;
import cn.puge.mertisfront.service.TestPayDesService;
import cn.puge.mertisfront.utils.OrderNoUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author LIJW
 * @since 2021-01-25
 */
@CrossOrigin
@RestController
@RequestMapping("/mertisfront/test-order")
public class TestOrderController {

    @Autowired
    private TestPayDesService testPayDesService;

    @Autowired
    private TestOrderService testOrderService;

    /**
     * 测试生成订单  并返回订单号
     */
    @GetMapping("getOrderId/{desId}")
    public R getOrder(@PathVariable String desId){

        TestPayDes testPayDes = testPayDesService.getById(desId);
        TestOrder testOrder = new TestOrder();
        testOrder.setTestDes(testPayDes.getDes());
        testOrder.setPrice(testPayDes.getPrice());
        testOrder.setTestpaydesId(testPayDes.getId());
        testOrder.setOrderNo(OrderNoUtil.getOrderNo());
        testOrderService.save(testOrder);
        return R.ok().data("orderId",testOrder.getOrderNo());

    }

    /**
     * 测试查询出订单
     */
    @GetMapping("getOderInfo/{orderNo}")
    public R getOderInfo(@PathVariable String orderNo ){

        QueryWrapper<TestOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("order_no",orderNo);
        TestOrder one = testOrderService.getOne(queryWrapper);
        return R.ok().data("orderInfo",one);
    }
}

